package com.jinzhi.jzweb.utils;

import com.jinzhi.jzweb.pojo.StuSignUpTeamVo;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class FractionUtil {


    public static List<StuSignUpTeamVo> teamList( List<StuSignUpTeamVo> mapList){
        List<StuSignUpTeamVo> mapLists=new ArrayList<>();
        for(StuSignUpTeamVo obj:mapList){
            checkNull(obj);


            double jg = obj.getScore1() + obj.getScore2() +obj.getScore3();
            jg = (jg / 3);
            BigDecimal bg = new BigDecimal(jg);
            double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            obj.setTeamSumA(f1);

            //A赛场个人统计
            double b=(obj.getScoingb1() + obj.getScoingb2() + obj.getScoingb3());
            b = (b / 3);
            b = b + (obj.getTotalScore() * 0.3);
            BigDecimal bp = new BigDecimal(b);
            double bs = bp.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            obj.setTeamSumB(bs);

            //C赛场个人统计
            Double c=(obj.getScoingc1() + obj.getScoingc2() + obj.getScoingc3());
            c = (c / 3);
            BigDecimal cp = new BigDecimal(c);
            double cs = cp.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            //c赛场
            obj.setTeamSumC(cs);


            Double tatlo=(f1+bs+cs);
            BigDecimal bgs = new BigDecimal(tatlo);
            double tatlos = bgs.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            // obj.setTeamSumC(tatlos);
            //计算俩个选手的总分
            obj.setTeamTotal(tatlos);
            mapLists.add(obj);
        }
        mapLists.sort((a,b) -> b.getTeamTotal().compareTo(a.getTeamTotal()));
        return mapLists;
    }

    private static void checkNull(StuSignUpTeamVo obj){
        //a1
        if(obj.getScoingb1()==null){
            obj.setScoingb1(0.0);
        }
        if(obj.getScoingb2()==null){
            obj.setScoingb2(0.0);
        }
        if(obj.getScoingb3()==null){
            obj.setScoingb3(0.0);
        }
        if(obj.getScoingb4()==null){
            obj.setScoingb4(0.0);
        }
        if(obj.getScoingb5()==null){
            obj.setScoingb5(0.0);
        }
        //a2
        if(obj.getScoingb1s()==null){
            obj.setScoingb1s(0.0);
        }
        if(obj.getScoingb2s()==null){
            obj.setScoingb2s(0.0);
        }
        if(obj.getScoingb3s()==null){
            obj.setScoingb3s(0.0);
        }
        if(obj.getScoingb4s()==null){
            obj.setScoingb4s(0.0);
        }
        if(obj.getScoingb5s()==null){
            obj.setScoingb5s(0.0);
        }

        //c1
        if(obj.getScoingc1()==null){
            obj.setScoingc1(0.0);
        }
        if(obj.getScoingc2()==null){
            obj.setScoingc2(0.0);
        }
        if(obj.getScoingc3()==null){
            obj.setScoingc3(0.0);
        }
        if(obj.getScoingc4()==null){
            obj.setScoingc4(0.0);
        }
        if(obj.getScoingc5()==null){
            obj.setScoingc5(0.0);
        }
        //c2
        if(obj.getScoingc2s()==null){
            obj.setScoingc2s(0.0);
        }
        if(obj.getScoingc1s()==null){
            obj.setScoingc1s(0.0);
        }
        if(obj.getScoingc3s()==null){
            obj.setScoingc3s(0.0);
        }
        if(obj.getScoingc4s()==null){
            obj.setScoingc4s(0.0);
        }
        if(obj.getScoingc5s()==null){
            obj.setScoingc5s(0.0);
        }
        //c3
        if(obj.getScoingc1ls()==null){
            obj.setScoingc1ls(0.0);
        }
        if(obj.getScoingc2ls()==null){
            obj.setScoingc2ls(0.0);
        }
        if(obj.getScoingc3ls()==null){
            obj.setScoingc3ls(0.0);
        }
        if(obj.getScoingc4ls()==null){
            obj.setScoingc4ls(0.0);
        }
        if(obj.getScoingc5ls()==null){
            obj.setScoingc5ls(0.0);
        }
        //A
        if(obj.getScore1()==null){
            obj.setScore1(0.0);
        }
        if(obj.getScore2()==null){
            obj.setScore2(0.0);
        }
        if(obj.getScore3()==null){
            obj.setScore3(0.0);
        }
        if(obj.getScore4()==null){
            obj.setScore4(0.0);
        }
        if(obj.getScore5()==null){
            obj.setScore5(0.0);
        }

        if(obj.getScore1s()==null){
            obj.setScore1s(0.0);
        }
        if(obj.getScore2s()==null){
            obj.setScore2s(0.0);
        }
        if(obj.getScore3s()==null){
            obj.setScore3s(0.0);
        }
        if(obj.getScore4s()==null){
            obj.setScore4s(0.0);
        }
        if(obj.getScore5s()==null){
            obj.setScore5s(0.0);
        }
    }
}
